<template>
  <div>
    <!-- 推荐列表数据 -->
    <van-list
      v-model:loading="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
    <!-- 下拉加载 -->
    <ul>
        <li v-for="item in list " :key="item">
          <RouterLink :to="'/details/' + item.proid">
            <img :src="item.img1" alt="">
            <p>{{ item.proname }}</p>
            <span>￥{{ item.originprice }}</span>
            </RouterLink>
        </li>
    </ul>
    </van-list>
  </div>
</template>

<script>
import { getListf } from "../../service/lists";
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      count: 1,
      limitNum: 10,
    };
  },
  methods: {
    onLoad() {
      // 异步更新数据
      getListf(this.count, this.limitNum).then((res) => {
        console.log(res.data.data);
        this.list = this.list.concat(res.data.data);
      });
      // 加载状态结束
      this.loading = false;
      this.count++;
      // 数据全部加载完成
      if (this.list.length >=150){
        this.finished = true;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
div{
    width: 100%;
    ul{
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        li{
            width: 50%;
            box-sizing: border-box;
            padding: 10px;
            img{
                display: block;
                width: 100%;
            }
            p{
                width: 100%;
                font-size: 17px;
                overflow: hidden;
                height: 40px;
            }
            span{
                color: red;
                font-size: 16px;
            }

        }
    }
}
a{
  color: black;
}
</style>
